<?php

class Progress_con extends CI_Controller {

    function __construct() {
        parent::__construct();
        //cek session
        if(!$this->session->userdata('islogin')){
            redirect(base_url().'progress/login_con');
        }
    }
    
    function index() {
        $this->personal_bio($this->session->userdata('id'));
    }
    function personal_bio($id){
        $display=array();
        $query=$this->db->query('select * from user where ID='.$id.'')->result_array();
        if(count($query)>0)
            $display['user'] = $query[0];
        $this->load->view('progress/header_view');
        $this->load->view('progress/personal_bio_view',$display);
        $this->load->view('progress/footer_view');        
    }
    function personal_bio_edit($id){
        $display=array();
        $query=$this->db->query('select * from user where ID='.$id.'')->result_array();
        if(count($query)>0){
            $display['user'] = $query[0];
            $tanggal = substr($query[0]['TANGGAL_LAHIR'], 8,2);
            $bulan = substr($query[0]['TANGGAL_LAHIR'], 5,2);
            $tahun = substr($query[0]['TANGGAL_LAHIR'], 0,4);
            $display['tanggal'] = $tanggal;
            $display['bulan'] = $bulan;
            $display['tahun'] = $tahun;
        }
        $this->load->view('progress/header_view');
        $this->load->view('progress/personal_bio_edit_view',$display);
        $this->load->view('progress/footer_view');        
    }
    function personal_bio_edit_process($id){
//        if(empty($_POST['nama']) || empty($_POST['tempat']) || empty($_POST['tanggal']) || empty($_POST['bulan']) || empty($_POST['tahun'])
//                || empty($_POST['telp']) || empty($_POST['alamat']) || empty($_POST['email']) || empty($_POST['rekening']))
//            redirect (base_url().'progress/progress_con/personal_bio/'.$id);
        $nama = $_POST['nama'];
        $tempat = $_POST['tempat'];
        $tanggal = $_POST['tanggal'];
        $bulan = $_POST['bulan'];
        $tahun = $_POST['tahun'];
        $telp = $_POST['telp'];
        $alamat = $_POST['alamat'];
        $email = $_POST['email'];
        $rekening = $_POST['rekening'];
        if($this->session->userdata('temp_foto')!=''){
            $data = array(
                'NAMA'=>$nama,
                'EMAIL'=>$email,
                'FOTO'=>$this->session->userdata('temp_foto'),
                'ALAMAT'=>$alamat,
                'NO_TELP'=>$telp,
                'NO_REK'=>$rekening,
                'TEMPAT_LAHIR'=>$tempat,
                'TANGGAL_LAHIR'=>$tahun.'-'.$bulan.'-'.$tanggal,
            );

        }else{
            $data = array(
                'NAMA'=>$nama,
                'EMAIL'=>$email,
                'ALAMAT'=>$alamat,
                'NO_TELP'=>$telp,
                'NO_REK'=>$rekening,
                'TEMPAT_LAHIR'=>$tempat,
                'TANGGAL_LAHIR'=>$tahun.'-'.$bulan.'-'.$tanggal,
            );
        }
        $this->db->where('ID',$id);
        $this->db->update('user', $data);
        redirect(base_url().'progress/progress_con/personal_bio/'.$id);
    }
    function personal_pos_self($id){
        $display=array();
        $query=$this->db->query('select * from jabatan_divisi natural join list_divisi where ID_USER='.$id.'')->result_array();
        if(count($query)>0)
            $display['position'] = $query;
        $user =$this->db->query('select * from user where ID='.$id.'')->result_array();
        if(count($user)>0)
            $display['user'] = $user[0];
        $this->load->view('progress/header_view');
        $this->load->view('progress/personal_pos_self_view',$display);
        $this->load->view('progress/footer_view');        
    }
    function personal_listpos($id){
        $display=array();
        
        $query=$this->db->query('select * from jabatan_divisi natural join list_divisi where ID_USER='.$id.'')->result_array();
        if(count($query)>0)
            $display['position'] = $query;
        $user =$this->db->query('select * from user where ID='.$id.'')->result_array();
        if(count($user)>0)
            $display['user'] = $user[0];
        //if(count($query)==1)
        //    redirect (base_url().'progress/progress_con/personal_pos/'.$id.'/'.$query[0]['ID_DIVISI']);
        $this->load->view('progress/header_view');
        $this->load->view('progress/personal_listpos_view',$display);
        $this->load->view('progress/footer_view');        
    }
    function personal_pos($idjab,$iduser, $iddivisi){
        $display=array();
        $query=$this->db->query('select * from jabatan_divisi where ID_USER='.$iduser)->result_array();
        $list_jabatan = array();
        if(count($query)>0){
            for($i=0;$i<count($query);$i++){
                if($query[$i]['ID_JABATAN']==$idjab)
                    $display['jabatan'] = $query[$i];
                else{
                    $list_jabatan[] = $query[$i];
                }
            }
        }
        $display['list_jabatan'] = $list_jabatan;
        $user =$this->db->query('select * from user where ID='.$iduser.'')->result_array();
        if(count($user)>0)
            $display['user'] = $user[0];
        $this->load->view('progress/header_view');
        $this->load->view('progress/personal_pos_view',$display);
        $this->load->view('progress/footer_view');        
    }
    function personal_pos_edit($idjab,$iduser, $iddivisi){
        $display=array();
        $query=$this->db->query('select * from jabatan_divisi where ID_JABATAN='.$idjab.'')->result_array();
        if(count($query)>0)
            $display['jabatan'] = $query[0];
        $user =$this->db->query('select * from user where ID='.$iduser.'')->result_array();
        if(count($user)>0)
            $display['user'] = $user[0];
        $this->load->view('progress/header_view');
        $this->load->view('progress/personal_pos_edit_view',$display);
        $this->load->view('progress/footer_view');        
    }
    function personal_pos_add($iduser){
        $display=array();
        $query=$this->db->query('select * from list_divisi')->result_array();
        if(count($query)>0)
            $display['list_divisi'] = $query;
        $user =$this->db->query('select * from user where ID='.$iduser.'')->result_array();
        if(count($user)>0)
            $display['user'] = $user[0];
        $this->load->view('progress/header_view');
        $this->load->view('progress/personal_pos_add_view',$display);
        $this->load->view('progress/footer_view');        
    }
    function personal_pos_add_process($iduser){
        if(!empty($_POST['posisi'])) {
            $data = array(
                'NAMA_JABATAN'=>$_POST['posisi'],
                'ID_DIVISI'=>$_POST['pilih'],
                'ID_USER'=>$iduser
            );
            $this->db->insert('jabatan_divisi' ,$data);
        }
        redirect(base_url().'progress/progress_con/personal_listpos/'.$iduser);
    }
    
    function personal_pos_delete($idjab,$iduser,$iddivisi){
        $display=array();
        $where = array(
            'ID_JABATAN'=>$idjab,
        );
        $this->db->where($where);
        $this->db->delete('jabatan_divisi');
        
        redirect(base_url().'progress/progress_con/personal_pos_self/'.$iduser.'/'.$iddivisi);
    }
    function personal_pos_edit_process($idjab,$iduser, $iddivisi){
        $display=array();
        $desc='';
        $gen1='';
        $gen2='';
        $gen3='';
        $gen4='';
        $gen5='';
        $rou1='';
        $rou2='';
        $rou3='';
        $rou4='';
        $rou5='';
        if(!empty($_POST['desc'])) $desc = $_POST['desc'];
        if(!empty($_POST['gen1'])) $gen1 = $_POST['gen1'];
        if(!empty($_POST['gen2'])) $gen2 = $_POST['gen2'];
        if(!empty($_POST['gen3'])) $gen3 = $_POST['gen3'];
        if(!empty($_POST['gen4'])) $gen4 = $_POST['gen4'];
        if(!empty($_POST['gen5'])) $gen5 = $_POST['gen5'];
        if(!empty($_POST['rou1'])) $rou1 = $_POST['rou1'];
        if(!empty($_POST['rou2'])) $rou2 = $_POST['rou2'];
        if(!empty($_POST['rou3'])) $rou3 = $_POST['rou3'];
        if(!empty($_POST['rou4'])) $rou4 = $_POST['rou4'];
        if(!empty($_POST['rou5'])) $rou5 = $_POST['rou5'];
        
        $data = array(
            'JOB_DESC'=>$desc,
            'GENTASK1'=>$gen1,
            'GENTASK2'=>$gen2,
            'GENTASK3'=>$gen3,
            'GENTASK4'=>$gen4,
            'GENTASK5'=>$gen5,
            'ROUTASK1'=>$rou1,
            'ROUTASK2'=>$rou3,
            'ROUTASK3'=>$rou3,
            'ROUTASK4'=>$rou4,
            'ROUTASK5'=>$rou5
        );
        $where = array(
            'ID_JABATAN'=>$idjab,
        );
        $this->db->where($where);
        $this->db->update('jabatan_divisi', $data);
        
        redirect(base_url().'progress/progress_con/personal_pos/'.$idjab.'/'.$iduser.'/'.$iddivisi);
    }
    function say_plain($option=1){
        if($option==2){ // with link
            $this->load->view('progress/header_view');
            $this->load->view('progress/say_withlink_view');
            $this->load->view('progress/footer_view');                    
        }else if($option==3){ //with picture
            $this->load->view('progress/header_view');
            $this->load->view('progress/say_withpic_view');
            $this->load->view('progress/footer_view');                    
        }else if($option==4){ //with file
            $this->load->view('progress/header_view');
            $this->load->view('progress/say_withfile_view');
            $this->load->view('progress/footer_view');                    
        }else{
            $this->load->view('progress/header_view');
            $this->load->view('progress/say_plain_view');
            $this->load->view('progress/footer_view');        
        }
    }
    function sayout_plain($option=1){
        if(empty($_POST['description']))
            redirect (base_url().'progress/progress_con/say_plain/'.$option);
        $desc=$_POST['description'];
        $link='';
        $jenis='plain';
        if($option==2){
            if(empty($_POST['link']))
                redirect (base_url().'progress/progress_con/say_plain/'.$option);
            $link = $_POST['link'];
             $jenis="link";
       }else if($option==3){
            if(empty($_FILES['userfile']['name']))
                redirect (base_url().'progress/progress_con/say_plain/'.$option);
            
            $path = realpath(APPPATH . '../progress_upload/');
            $config = array(
                'allowed_types'=>'jpg|jpeg|gif|png',
                'upload_path' => $path,
                'max_size' => 20000,
            );
            $this->load->library('upload',$config);
            $this->upload->do_custom_upload('Progress_'.$this->session->userdata('id').'_'.date('Y-m-d_H-i-s'),'userfile');
            $s= $this->upload->data();
            $link=base_url().'progress_upload/'.$s['file_name'];
            //echo $s['file_name'];
            $jenis="picture";
        }else if($option==4){
            if(empty($_FILES['userfile']['name']))
                redirect (base_url().'progress/progress_con/say_plain/'.$option);
            $path = realpath(APPPATH . '../progress_upload/');
            $config = array(
                'allowed_types'=>'*',
                'upload_path' => $path,
                'max_size' => 20000,
            );
            $this->load->library('upload',$config);
            $this->upload->do_custom_upload('Progress_'.$this->session->userdata('id').'_'.date('Y-m-d_H-i-s'),'userfile');
            $s= $this->upload->data();
            //echo $s['file_name'];
            $link=base_url().'progress_upload/'.$s['file_name'];
            $jenis="file";
        }
        $data=array(
            'ID_USER'=>$this->session->userdata('id'),
            'DESC_PROGRESS'=>$desc,
            'JENIS'=>$jenis,
            'LINK'=>$link,
            'TGL'=>date('Y-m-d'),
            'WAKTU'=>date('H:i:s')
        );
        $this->db->insert('progress_report', $data);
        redirect(base_url().'progress/progress_con/progress');
    }
    function todo_making(){
        $display=array();
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['divisi'] = $query;
        $query = $this->db->query('select * from progress_user inner join user on progress_user.ID_USER =user.ID')->result_array();
        $display['user'] = $query;
        
        
        $this->load->view('progress/header_view');
        $this->load->view('progress/todo_making_view', $display);
        $this->load->view('progress/footer_view');        
    }
    function todo_making_process($option=1){
        if($option==1){
            if(empty($_POST['todo1']) || empty($_POST['date1']))
                redirect (base_url().'progress/progress_con/todo_making');
            $todo = $_POST['todo1'];
            $date = $_POST['date1'];
            $urgent = 0;
            if(!empty($_POST['urgent1']))
                $urgent = 1;
            $idto = $this->session->userdata('id');
        }else if($option==2){ // divisi
            if(empty($_POST['todo2']) || empty($_POST['date2']))
                redirect (base_url().'progress/progress_con/todo_making');
            $todo = $_POST['todo2'];
            $date = $_POST['date2'];
            $urgent = 0;
            if(!empty($_POST['urgent2']))
                $urgent = 1;            
            $idto = $_POST['select_divisi'];
        }else if($option==3){ // personal
            if(empty($_POST['todo3']) || empty($_POST['date3']))
                redirect (base_url().'progress/progress_con/todo_making');
            $todo = $_POST['todo3'];
            $date = $_POST['date3'];
            $urgent = 0;
            if(!empty($_POST['urgent3']))
                $urgent = 1;            
            $idto = $_POST['select_user'];            
        }
        
        if($option==1 || $option==3){
            $data = array(
                'ID_USER' => $idto,
                'ISI_TODO' => $todo,
                'STATUS_URGENT' => $urgent,
                'DEADLINE'=> substr($date, 6,4).'-'.substr($date,0,2).'-'.substr($date, 3,2),
                'ID_PEMBERI_TODO'=>$this->session->userdata('id'),
                'STATUS_PENGERJAAN' =>'',
                'KOMENTAR_PENGERJAAN'=>'',
            );
            $this->db->insert('todo_personal', $data);
        }
        if($option==2){
            $data = array(
                'ID_DIVISI' => $idto,
                'DESKRIPSI_TODO' => $todo,
                'STATUS_URGENT' => $urgent,
                'DEADLINE'=> substr($date, 6,4).'-'.substr($date,0,2).'-'.substr($date, 3,2),
                'ID_PEMBERI_TODO'=>$this->session->userdata('id'),
                'STATUS_PENGERJAAN' =>'',
                'KOMENTAR_PENGERJAAN'=>'',
            );
            $this->db->insert('todo_divisi', $data);
        }
        redirect(base_url().'progress/progress_con/todo');
    }
    function complain(){
        $this->load->view('progress/header_view');
        $this->load->view('progress/complain_view');
        $this->load->view('progress/footer_view');        
    }
    function complain_process(){
        if(empty($_POST['complain']))
            redirect(base_url().'progress/progress_con/complain');
        $complain = $_POST['complain'];
        $data = array(
            'ID_USER' => $this->session->userdata('id'),
            'ISI_KOMPLAIN' => $complain,
            'ID_HANDLER' => '',
            'ID_DIVISI' => '',
            'STATUS_HANDLING' => '',
            'KOMENTAR_HANDLING' => '',
            'TGL_KOMPLAIN' => date('Y-m-d'),
            'WAKTU_KOMPLAIN' => date('H:i:s')
        );
        $this->db->insert('komplain', $data);
        redirect(base_url().'progress/progress_con/problem');
    }
    function isIdExist($id, $list){
        $found = false;
        $counter=0;
        while($counter<count($list) && !$found){
            if($list[$counter]['ID_USER']==$id)
                $found = true;
            $counter+=1;
        }
        return $found;
    }
    function progress($option=1, $id_divisi=-1, $hal=1){ //1 = last 10, 2 = today, 3 = this month
        $display=array();
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['list_divisi'] = $query;
        if($option==1){ // last 10
            $query = $this->db->query('select * from progress_report inner join user on progress_report.ID_USER=user.ID order by TGL desc, WAKTU desc LIMIT 10')->result_array();
        }else if($option==2){ // today
            $query = $this->db->query('select * from progress_report inner join user on progress_report.ID_USER=user.ID where TGL="'.date('Y-m-d').'" order by TGL desc, WAKTU desc')->result_array();
        }else if($option==3){ // this month
            $query = $this->db->query('select * from progress_report inner join user on progress_report.ID_USER=user.ID order by TGL desc, WAKTU desc')->result_array();
            $temp = array();
            for($i=0;$i<count($query);$i++){
                if(substr($query[$i]['TGL'], 0,7) ==date('Y-m'))
                    $temp[] = $query[$i];
            }            
            $query = array();
            $query = $temp;
        }else
            redirect (base_url().'progress/progress_con/progress');
        $progress = array();
        if($id_divisi!=-1){
            $id_user = $this->db->query('select * from jabatan_divisi where ID_DIVISI='.$id_divisi)->result_array();
            for($i=0;$i<count($query);$i++){
                if($id_divisi!=-1){
                    if($this->isIdExist($query[$i]['ID_USER'], $id_user)){
                        $progress[] = $query[$i];
                    }
                }
            }
        }else $progress = $query;
        for($i=0;$i<count($progress);$i++){
            $like = $this->db->query('select count(ID_USER) as jumlah from liked_progress where ID_PROGRESS='.$progress[$i]['ID_PROGRESS'])->result_array();
            if(count($like)>0)
                $progress[$i]['LIKE'] = $like[0]['jumlah'];
            else $progress[$i]['LIKE'] = 0;
        }

        $max_tab = 10;
        $count=count($progress);
        $add=0;
        $div = $max_tab;
        if ($count%$div!=0){
            $add=1;
        }
        $page = ($count - ($count%$div))/$div+$add;
        
        $j=0;
        $content = array();
        while($j<$max_tab && $j<count($progress) - ($hal-1)*$max_tab){
            $content[$j] = $progress[(($hal-1)*$max_tab)+$j];
            $j+=1;
        }
        $display['progress'] = $content;
        $display['page'] = $page;
        $display['curr_page'] = $hal;
        $display['option'] = $option;
        $display['id_divisi'] = $id_divisi;
        
        $this->load->view('progress/header_view');
        $this->load->view('progress/progress_view', $display);
        $this->load->view('progress/footer_view');                
    }
    function progress_personal(){
        $display=array();
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['list_divisi'] = $query;
        $query = $this->db->query('select * from progress_user inner join user on progress_user.ID_USER=user.ID')->result_array();
        for($i=0;$i<count($query);$i++){
            $count = $this->db->query('select count(ID_USER) as jumlah from progress_report where ID_USER='.$query[$i]['ID_USER'])->result_array();
            if(count($count)>0)
            $query[$i]['COUNT_PROGRESS'] = $count[0]['jumlah'];
            else $query[$i]['COUNT_PROGRESS'] = 0;
            
//            $like = $this->db->query('select count(ID_USER) as jumlah from liked_progress where ID_PROGRESS='.$query[$i]['ID_PROGRESS'])->result_array();
//            if(count($like)>0)
//            $query[$i]['LIKE'] = $like[0]['jumlah'];
//            else 
                $query[$i]['LIKE'] = 0;
        }
        $display['user'] = $query;
        $this->load->view('progress/header_view');
        $this->load->view('progress/progress_personal_view', $display);
        $this->load->view('progress/footer_view');
    }
    function progress_personal_detail($id_user, $option=1, $id_divisi=-1, $hal=1){
        $display=array();
        
        $query = $this->db->query('select * from user where ID='.$id_user)->result_array();
        if(count($query)>0)
        $display['user'] = $query[0];
        
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['list_divisi'] = $query;
        if($option==1){ // last 10
            $query = $this->db->query('select * from progress_report inner join user on progress_report.ID_USER=user.ID where ID_USER='.$id_user.' order by TGL desc, WAKTU desc LIMIT 10')->result_array();
        }else if($option==2){ // this month
            $query = $this->db->query('select * from progress_report inner join user on progress_report.ID_USER=user.ID where ID_USER='.$id_user.' order by TGL desc, WAKTU desc')->result_array();
            $temp = array();
            for($i=0;$i<count($query);$i++){
                if(substr($query[$i]['TGL'], 0,7) ==date('Y-m'))
                    $temp[] = $query[$i];
            }            
            $query = array();
            $query = $temp;
        }else if($option==3){ // last month
            $query = $this->db->query('select * from progress_report inner join user on progress_report.ID_USER=user.ID where ID_USER='.$id_user.' order by TGL desc, WAKTU desc')->result_array();
            $temp = array();

            for($i=0;$i<count($query);$i++){
                if(substr($query[$i]['TGL'], 0,7) ==date("Y-m", strtotime("-1 month") ))
                    $temp[] = $query[$i];
            }            
            $query = array();
            $query = $temp;
        }else
            redirect (base_url().'progress/progress_con/progress');
        $progress = array();
        if($id_divisi!=-1){
            $id_user = $this->db->query('select * from jabatan_divisi where ID_DIVISI='.$id_divisi)->result_array();
            for($i=0;$i<count($query);$i++){
                if($id_divisi!=-1){
                    if($this->isIdExist($query[$i]['ID_USER'], $id_user)){
                        $progress[] = $query[$i];
                    }
                }
            }
        }else $progress = $query;
        for($i=0;$i<count($progress);$i++){
            $like = $this->db->query('select count(ID_USER) as jumlah from liked_progress where ID_PROGRESS='.$progress[$i]['ID_PROGRESS'])->result_array();
            if(count($like)>0)
                $progress[$i]['LIKE'] = $like[0]['jumlah'];
            else $progress[$i]['LIKE'] = 0;
        }

        $max_tab = 10;
        $count=count($progress);
        $add=0;
        $div = $max_tab;
        if ($count%$div!=0){
            $add=1;
        }
        $page = ($count - ($count%$div))/$div+$add;
        
        $j=0;
        $content = array();
        while($j<$max_tab && $j<count($progress) - ($hal-1)*$max_tab){
            $content[$j] = $progress[(($hal-1)*$max_tab)+$j];
            $j+=1;
        }
        $display['progress'] = $content;
        $display['page'] = $page;
        $display['curr_page'] = $hal;
        $display['option'] = $option;
        $display['id_divisi'] = $id_divisi;
        
        $this->load->view('progress/header_view');
        $this->load->view('progress/progress_personal_detail_view', $display);
        $this->load->view('progress/footer_view');
        
    }
    
    function progress_like($id_progress){
        $query = $this->db->query('select * from liked_progress where ID_PROGRESS='.$id_progress.' and ID_USER='.$this->session->userdata('id'))->result_array();    
        if(count($query)<=0){
            $data = array(
                'ID_USER' => $this->session->userdata('id'),
                'TGL' => date('Y-m-d'),
                'WAKTU' => date('H:i:s'),
                'ID_PROGRESS' => $id_progress
            );
            $this->db->insert('liked_progress', $data);
        }
        redirect(base_url().'progress/progress_con/progress');
    }
        
        

    function todo($urgent = 0, $id_divisi=-2, $hal=1){
        $display=array();
        $status='where STATUS_PENGERJAAN=""';
        if($urgent == 1)
            $status .= ' and STATUS_URGENT=1';
        if($id_divisi>=0){ // divisi tertentu
            $todo = array();
            $status .=' and todo_divisi.ID_DIVISI='.$id_divisi;
        }else{ // semua divisio
            $query = $this->db->query('select * from todo_personal inner join user on todo_personal.ID_USER=user.ID '.$status)->result_array();            
            $todo = $query;
        }
        $query = $this->db->query('select * from todo_divisi inner join list_divisi on todo_divisi.ID_DIVISI=list_divisi.ID_DIVISI '.$status)->result_array();
        for($i=0;$i<count($query);$i++)
            array_push($todo, $query[$i]);
        
        
        $urut_penawar = $todo;
        for($x = 0; $x < count($urut_penawar); $x++) {
            for($y = 0; $y < count($urut_penawar); $y++) {
                if($urut_penawar[$x]['DEADLINE'] < $urut_penawar[$y]['DEADLINE']) {
                    $hold = $urut_penawar[$x];
                    $urut_penawar[$x] = $urut_penawar[$y];
                    $urut_penawar[$y] = $hold;
                }
            }
        }
        $todo = $urut_penawar;
        
        if($id_divisi==-1){
            $temp = array();
            for($i=0;$i<count($todo);$i++){
                if(substr($todo[$i]['DEADLINE'],0,7)==date('Y-m'))
                    $temp[] = $todo[$i];
            }
            $todo = array();
            $todo = $temp;
        }
        
        
        $max_tab = 10;
        $count=count($todo);
        $add=0;
        $div = $max_tab;
        if ($count%$div!=0){
            $add=1;
        }
        $page = ($count - ($count%$div))/$div+$add;
        
        $j=0;
        $content = array();
        while($j<$max_tab && $j<count($todo) - ($hal-1)*$max_tab){
            $content[$j] = $todo[(($hal-1)*$max_tab)+$j];
            $j+=1;
        }
        $display['todo'] = $content;
        $display['page'] = $page;
        $display['curr_page'] = $hal;
        $display['urgent']= $urgent;
        $display['id_divisi']= $id_divisi;
        
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['list_divisi'] = $query;
        
        $this->load->view('progress/header_view');
        $this->load->view('progress/todo_view', $display);
        $this->load->view('progress/footer_view');                
    }
    function todo_personal_me(){
        $display=array();
        $query = $this->db->query('select * from todo_personal where STATUS_PENGERJAAN="" and ID_USER='.$this->session->userdata('id').' order by DEADLINE asc')->result_array();
        $display['todo_personal'] = $query;
        $query = $this->db->query('select * from todo_divisi inner join jabatan_divisi on todo_divisi.ID_DIVISI=jabatan_divisi.ID_DIVISI  where STATUS_PENGERJAAN="" and ID_USER='.$this->session->userdata('id').' order by DEADLINE asc')->result_array();
        $display['todo_divisi'] = $query;
        
        $this->load->view('progress/header_view');
        $this->load->view('progress/todo_personal_me_view', $display);
        $this->load->view('progress/footer_view');        
    }
    function todo_personal($filterdivisi=-1){
        $display=array();
        
        if($filterdivisi>=0){
            $user = $this->db->query('select * from jabatan_divisi inner join user on jabatan_divisi.ID_USER=user.ID where ID_DIVISI='.$filterdivisi)->result_array();
        }
        else{
            $user = $this->db->query('select * from progress_user inner join user on progress_user.ID_USER=user.ID')->result_array();
        }
        
        for($i=0;$i<count($user);$i++){
            $query = $this->db->query('select * from todo_personal inner join user on todo_personal.ID_USER=user.ID where STATUS_PENGERJAAN="" and user.ID='.$user[$i]['ID_USER'])->result_array();
            $todo = $query;
            $query = $this->db->query('select * from todo_divisi inner join jabatan_divisi on todo_divisi.ID_DIVISI=jabatan_divisi.ID_DIVISI where STATUS_PENGERJAAN="" and jabatan_divisi.ID_USER='.$user[$i]['ID_USER'])->result_array();
            for($j=0;$j<count($query);$j++)
                array_push($todo, $query[$j]);
            
            if($filterdivisi==-1){
                $temp = array();
                for($j=0;$j<count($todo);$j++){
                    if(substr($todo[$j]['DEADLINE'],0,7)==date('Y-m'))
                        $temp[] = $todo[$j];
                }
                $todo = array();
                $todo = $temp;
            }
            
            $user[$i]['TODO'] = $todo;
        }

        $display['user'] = $user;
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['list_divisi'] = $query;
        $this->load->view('progress/header_view');
        $this->load->view('progress/todo_personal_view', $display);
        $this->load->view('progress/footer_view');        
    }
    
    function todo_personal_occasional($id_user){
        $display=array();
        $user = $this->db->query('select * from progress_user inner join user on progress_user.ID_USER=user.ID where user.ID='.$id_user)->result_array();
        if(count($user)>0){
            $user = $user[0];
            $query = $this->db->query('select * from todo_personal inner join user on todo_personal.ID_USER=user.ID where STATUS_PENGERJAAN="" and user.ID='.$id_user)->result_array();
            $todo = $query;
            $query = $this->db->query('select * from todo_divisi inner join jabatan_divisi on todo_divisi.ID_DIVISI=jabatan_divisi.ID_DIVISI where STATUS_PENGERJAAN="" and jabatan_divisi.ID_USER='.$id_user)->result_array();
            for($j=0;$j<count($query);$j++)
                array_push($todo, $query[$j]);
            
                    
            $urut_penawar = $todo;
            for($x = 0; $x < count($urut_penawar); $x++) {
                for($y = 0; $y < count($urut_penawar); $y++) {
                    if($urut_penawar[$x]['DEADLINE'] < $urut_penawar[$y]['DEADLINE']) {
                        $hold = $urut_penawar[$x];
                        $urut_penawar[$x] = $urut_penawar[$y];
                        $urut_penawar[$y] = $hold;
                    }
                }
            }
            $todo = $urut_penawar;

            $user['TODO'] = $todo;
        }
        $display['user'] = $user;
        $this->load->view('progress/header_view');
        $this->load->view('progress/todo_personal_occasional_view', $display);
        $this->load->view('progress/footer_view');        
    }
    function todo_personal_routine($id_user){
        $display=array();
        $user = $this->db->query('select * from progress_user inner join user on progress_user.ID_USER=user.ID where user.ID='.$id_user)->result_array();
        if(count($user)>0){
            $user = $user[0];
            $query = $this->db->query('select * from jabatan_divisi where ID_USER='.$id_user)->result_array();
            $user['ROUTASK'] = $query;
        }
        $display['user'] = $user;
        $this->load->view('progress/header_view');
        $this->load->view('progress/todo_personal_routine_view', $display);
        $this->load->view('progress/footer_view');        
    }
    function todo_done($option, $id_todo){ // opsi 1= personal, 2 = divisi
        $display=array();
        if($option==1){
            $query = $this->db->query('select * from todo_personal inner join user on todo_personal.ID_PEMBERI_TODO=user.ID where ID_TODO='.$id_todo)->result_array();
            if(count($query)>0){
                if($query[0]['ID_USER']==$this->session->userdata('id'))
                    $query[0]['BERHAK'] = true;
                $display['todo'] = $query[0];
            }
        }
        else if($option==2){
            $query = $this->db->query('select * from todo_divisi inner join user on todo_divisi.ID_PEMBERI_TODO=user.ID inner join list_divisi on todo_divisi.ID_DIVISI=list_divisi.ID_DIVISI where ID_TODO='.$id_todo)->result_array();
            if(count($query)>0){
                $mydivisi = $this->db->query('select * from jabatan_divisi where ID_USER='.$this->session->userdata('id'))->result_array();
                for($j=0;$j<count($mydivisi);$j++){
                    if($mydivisi[$j]['ID_DIVISI']==$query[0]['ID_DIVISI']){
                        $query[0]['BERHAK'] = true;
                    }
                }

                $display['todo'] = $query[0];
            }
        }
        $display['option'] = $option;
        $display['id_todo'] = $id_todo;
        $this->load->view('progress/header_view');
        $this->load->view('progress/todo_done_view', $display);
        $this->load->view('progress/footer_view');
    }
    
    function todo_done_process($option, $id_todo){
        if(empty($_POST['komentar']))
            redirect (base_url().'progress/progress_con/todo');
        $komentar = $_POST['komentar'];
        $data = array(
            'KOMENTAR_PENGERJAAN' => $komentar,
            'STATUS_PENGERJAAN' => 'DONE'
        );
        $this->db->where('ID_TODO', $id_todo);
        if($option==1){
            $this->db->update('todo_personal', $data);
            
        }else if($option==2){        
            $this->db->update('todo_divisi', $data);
        }
        redirect(base_url().'progress/progress_con/todo');
    }

    function absen(){
        $display = array();
        $query = $this->db->query('select * from term where STATUS="SEDANG"')->result_array();
        if(count($query)<=0)
            redirect (base_url().'progress/progress_con/absen');
        $term = $query[0];
        $display['term'] = $term;
        $kelas = $this->db->query('select * from kelas inner join pelatihan on kelas.KODE_PELATIHAN=
            pelatihan.KODE_PELATIHAN where TERM='.$term['NO_TERM'].' and TAHUN='.$term['TAHUN'])->result_array();
        for($i=0;$i<count($kelas);$i++){
            $list_sesi = array();
            $query = $this->db->query('select * from daftar_jadwal where KODE_PELATIHAN="'.$kelas[$i]['KODE_PELATIHAN'].'"
                and ANGKATAN='.$kelas[$i]['ANGKATAN'].' order by TANGGAL asc')->result_array();
            $finish=false;
            $counter=0;
            while(!$finish && $counter<count($query)){
                if(date('Y-m-d')>=$query[$counter]['TANGGAL'])
                    $list_sesi[] = $query[$counter];
                else
                    $finish = true;
                $counter+=1;
            }
            $total_sesi = $kelas[$i]['JAM_TOTAL']/$kelas[$i]['JAM_PER_SESI'];
            $sesi = 0;
            if(count($list_sesi)>0)
                $sesi = count($list_sesi)/$total_sesi*100;
            $kelas[$i]['PERSENTASE'] = $sesi;
            
        }
        $display['kelas'] = $kelas;
        $this->load->view('progress/header_view');
        $this->load->view('progress/absen_view', $display);
        $this->load->view('progress/footer_view');                
    }
    function absen_course($kode, $angk){
        $display = array();
        $kelas = $this->db->query('select * from kelas inner join pelatihan on kelas.KODE_PELATIHAN=
            pelatihan.KODE_PELATIHAN where kelas.KODE_PELATIHAN="'.$kode.'" and kelas.ANGKATAN='.$angk)->result_array();
        if(count($kelas)<=0)
            redirect (base_url().'progress/progress_con/absen');
        $display['kelas'] = $kelas[0];
        
        $jadwal = $this->db->query('select * from daftar_jadwal where KODE_PELATIHAN="'.$kode.'" AND ANGKATAN='.$angk.' order by TANGGAL asc')->result_array();
        $list_sesi = array();
        $finish = false;
        $counter=0;
        $list_id_instruktur = array();
        $list_id_asisten = array();
        $list_instruktur = array();
        $list_asisten = array();

        while(!$finish && $counter<count($jadwal)){
            $pengajar = $this->db->query('select * from ajar natural join user where KODE_PELATIHAN="'.$kode.'" AND ANGKATAN='.$angk.' AND NOMOR_SESI='.$jadwal[$counter]['NOMOR_SESI'])->result_array();
            for($j=0;$j<count($pengajar);$j++){
                if($pengajar[$j]['PERAN']=='instruktur'){
                    $jadwal[$counter]['INSTRUKTUR'] = $pengajar[$j];
                    if(!in_array($pengajar[$j]['ID'], $list_id_instruktur)){
                        $list_id_instruktur[] = $pengajar[$j]['ID'];
                        $list_instruktur[$pengajar[$j]['ID']]['COUNT'] = 1;
                        $list_instruktur[$pengajar[$j]['ID']]['NAMA'] = $pengajar[$j]['NAMA'];
                    }else{
                        $list_instruktur[$pengajar[$j]['ID']]['COUNT'] += 1;
                    }
                }
                else if($pengajar[$j]['PERAN']=='asisten'){
                    if(empty($jadwal[$counter]['ASISTEN1'])){
                        $jadwal[$counter]['ASISTEN1'] = $pengajar[$j];
                    }else{
                        $jadwal[$counter]['ASISTEN2'] = $pengajar[$j];                        
                    }
                    if(!in_array($pengajar[$j]['ID'], $list_id_asisten)){
                        $list_id_asisten[] = $pengajar[$j]['ID'];
                        $list_asisten[$pengajar[$j]['ID']]['COUNT'] = 1;
                        $list_asisten[$pengajar[$j]['ID']]['NAMA'] = $pengajar[$j]['NAMA'];
                    }else{
                        $list_asisten[$pengajar[$j]['ID']]['COUNT'] += 1;
                    }
                }
            }
            if(empty($jadwal[$counter]['INSTRUKTUR']))
                $jadwal[$counter]['INSTRUKTUR'] = '-';
            if(empty($jadwal[$counter]['ASISTEN1']))
                $jadwal[$counter]['ASISTEN1'] = '-';
            if(empty($jadwal[$counter]['ASISTEN2']))
                $jadwal[$counter]['ASISTEN2'] = '-';
            if(date('Y-m-d')>=$jadwal[$counter]['TANGGAL']){
                $list_sesi[] = $jadwal[$counter];
            }
            else{
                $finish = true;
            }
            $counter+=1;
        }
        $display['list_sesi']= $list_sesi;
        $display['list_instruktur']= $list_instruktur;
        $display['list_id_instruktur']= $list_id_instruktur;
        $display['list_asisten']= $list_asisten;
        $display['list_id_asisten']= $list_id_asisten;
        
        $this->load->view('progress/header_view');
        $this->load->view('progress/absen_course_view', $display);
        $this->load->view('progress/footer_view');                
        
    }

    function file(){
        $this->load->view('progress/header_view');
        $this->load->view('progress/file_view');
        $this->load->view('progress/footer_view');                
    }

    function countProblemStat($array, $id_divisi, $status){
        $result = 0;
        for($i=0;$i<count($array);$i++){
            if($array[$i]['ID_DIVISI'] == $id_divisi && $array[$i]['STATUS_HANDLING']==$status)
                $result+=1;
        }
        return $result;
    }
    
    function problem(){
        $display = array();
        $query = $this->db->query('select * from komplain where (ID_DIVISI<>0 and ID_DIVISI<>-1)')->result_array();
        $problem = $query;
        $query = $this->db->query('select * from komentar_sesi where (ID_DIVISI<>0 and ID_DIVISI<>-1)')->result_array();
        for($j=0;$j<count($query);$j++)
            array_push($problem, $query[$j]);
//        $display['problem'] = $todo;
        $list_divisi = $this->db->query('select * from list_divisi')->result_array();
        $summary['NEW'] = 0;
        $summary['HANDLED'] = 0;
        $summary['REJECTED'] = 0;
        $summary['SOLVED'] = 0;
        for($i=0;$i<count($list_divisi);$i++){
            $list_divisi[$i]['NEW'] = $this->countProblemStat($problem, $list_divisi[$i]['ID_DIVISI'], 'NEW');
            $list_divisi[$i]['HANDLED'] = $this->countProblemStat($problem, $list_divisi[$i]['ID_DIVISI'], 'HANDLED');
            $list_divisi[$i]['REJECTED'] = $this->countProblemStat($problem, $list_divisi[$i]['ID_DIVISI'], 'REJECTED');
            $list_divisi[$i]['SOLVED'] = $this->countProblemStat($problem, $list_divisi[$i]['ID_DIVISI'], 'SOLVED');
            $summary['NEW'] += $list_divisi[$i]['NEW'];
            $summary['HANDLED'] += $list_divisi[$i]['HANDLED'];
            $summary['REJECTED'] += $list_divisi[$i]['REJECTED'];
            $summary['SOLVED'] += $list_divisi[$i]['SOLVED'];
            //echo $list_divisi[$i]['NAMA_DIVISI'].':'.$list_divisi[$i]['NEW'].'<br>';
        }
        $display['list_divisi'] = $list_divisi;
        $display['summary'] = $summary;

        $this->load->view('progress/header_view');
        $this->load->view('progress/problem_view', $display);
        $this->load->view('progress/footer_view');                
    }
    
    function problem_manage($option=1, $hal=1){
        $display=array();
        if($option==1){
            $query = $this->db->query('select * from komplain inner join user on komplain.ID_USER=user.ID where ID_DIVISI=0 and (STATUS_HANDLING="" OR STATUS_HANDLING="NEW")')->result_array();
            $problem = $query;
        }else if($option==2){
            $query = $this->db->query('select * from komentar_sesi inner join user on komentar_sesi.ID=user.ID where ID_DIVISI=0 and (STATUS_HANDLING="" OR STATUS_HANDLING="NEW") limit 100 ')->result_array();
            $problem = $query;            
        }
        $display['option'] = $option;

        $max_tab = 10;
        $count=count($problem);
        $add=0;
        $div = $max_tab;
        if ($count%$div!=0){
            $add=1;
        }
        $page = ($count - ($count%$div))/$div+$add;
        
        $j=0;
        $content = array();
        while($j<$max_tab && $j<count($problem) - ($hal-1)*$max_tab){
            $content[$j] = $problem[(($hal-1)*$max_tab)+$j];
            $j+=1;
        }
        $display['problem'] = $content;
        $display['page'] = $page;
        $display['curr_page'] = $hal;
        
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['list_divisi'] = $query;
        $this->load->view('progress/header_view');
        $this->load->view('progress/problem_manage_view', $display);
        $this->load->view('progress/footer_view');        
    }
    
    function problem_manage_process(){
        if(empty($_POST['list_problem'])){
            redirect(base_url().'progress/progress_con/problem_manage');
        }
        $list = $_POST['list_problem'];
        foreach ($list as $value) {
            if($value!=0){
                $splitter = explode("_", $value);
                if($splitter[0]==1){ //komplain
                    $id_komplain = $splitter[1];
                    $id_divisi = $splitter[2];
                    if($id_divisi==-1)
                        $data = array(
                            'ID_DIVISI'=>$id_divisi
                        );
                    else
                        $data = array(
                            'ID_DIVISI'=>$id_divisi,
                            'STATUS_HANDLING' =>'NEW'
                        );
                    $this->db->where('ID_KOMPLAIN',$id_komplain);
                    $this->db->update('komplain', $data);                    
                }else if($splitter[0]==2){ // sf
                    $splitter_id = explode("-", $splitter[1]);
                    $id = $splitter_id[0];
                    $kode = $splitter_id[1];
                    $angk = $splitter_id[2];
                    $sesi = $splitter_id[3];
                    
                    $id_divisi = $splitter[2];
                    if($id_divisi==-1)
                        $data = array(
                            'ID_DIVISI'=>$id_divisi
                        );
                    else
                        $data = array(
                            'ID_DIVISI'=>$id_divisi,
                            'STATUS_HANDLING' =>'NEW'
                        );
                    $where = array(
                        'ID' => $id,
                        'KODE_PELATIHAN' => $kode,
                        'ANGKATAN' =>$angk,
                        'NOMOR_SESI' => $sesi,
                    );
                    $this->db->where($where);
                    $this->db->update('komentar_sesi', $data);                                        
                }
            }
        }
        redirect(base_url().'progress/progress_con/problem');
    }
    function isMyDivisi($list, $mydivisi){
        $result = false;
        for($i=0;$i<count($list);$i++){
            for($j=0;$j<count($mydivisi);$j++){
                if($mydivisi[$j]['ID_DIVISI']==$list[$i]['ID_DIVISI']){
                    $result = true;
                    break;
                }
            }
        }
        return $result;
    }
    function isMemberDivisi($listdivisi, $mydivisi){
        $result = false;
        for($i=0;$i<count($listdivisi);$i++){
            for($j=0;$j<count($mydivisi);$j++){
                if($mydivisi[$j]['ID_USER']==$listdivisi[$i]['ID_USER']){
                    $result = true;
                    break;
                }
            }
        }
        return $result;
    }
    
    function problem_page($stat='new',$id=-1, $hal=1){
        $display = array();
        $status=strtoupper($stat);
        $where = " where ID_DIVISI=".$id.' and STATUS_HANDLING="'.$status.'"';
        if($id==-1){
            $where = ' where ID_DIVISI<>0 and ID_DIVISI<>-1 and STATUS_HANDLING="'.$status.'"';        
            $display['divisi'] = 'All Division';            
        }else{
            $query = $this->db->query('select * from list_divisi where ID_DIVISI='.$id)->result_array();
            $display['divisi'] = $query[0]['NAMA_DIVISI'];            
        }
        $mydivisi = $this->db->query('select * from jabatan_divisi where ID_USER='.$this->session->userdata('id'))->result_array();
        
        if($status=="NEW")
            $query = $this->db->query('select * from komplain inner join user on komplain.ID_USER=user.ID'.$where)->result_array();
        else if($status=="HANDLED" || $status=="REJECTED" ||  $status=="SOLVED")
            $query = $this->db->query('select *, handler.NAMA as HANDLER from komplain inner join user as handler on komplain.ID_HANDLER=handler.ID inner join user on komplain.ID_USER=user.ID'.$where)->result_array();
        for($j=0;$j<count($query);$j++){
            if($this->isMyDivisi($query, $mydivisi)){
               $query[$j]['ANGGOTA_DIVISI'] = true;
            }
        }
        $problem = $query;
        
        if($status=="NEW")
            $query = $this->db->query('select * from komentar_sesi inner join user on komentar_sesi.ID=user.ID'.$where.' limit 100')->result_array();
        else if($status=="HANDLED" || $status=="REJECTED" ||  $status=="SOLVED")
            $query = $this->db->query('select *, handler.NAMA as HANDLER from komentar_sesi inner join user as handler on komentar_sesi.ID_HANDLER=handler.ID inner join user on komentar_sesi.ID=user.ID'.$where.' limit 10')->result_array();
        for($j=0;$j<count($query);$j++){
            if($this->isMyDivisi($query, $mydivisi)){
               $query[$j]['ANGGOTA_DIVISI'] = true;
            }
            $tanggal = $this->db->query('select * from daftar_jadwal inner join daftar_ruangan on daftar_jadwal.ID_RUANGAN=daftar_ruangan.ID_RUANGAN where KODE_PELATIHAN="'.$query[$j]['KODE_PELATIHAN'].'" AND ANGKATAN='.$query[$j]['ANGKATAN'].' AND NOMOR_SESI='.$query[$j]['NOMOR_SESI'].'')->result_array();
            if(count($tanggal)>0){
                $query[$j]['TANGGAL'] = $tanggal[0]['TANGGAL'];
                $query[$j]['NAMA_RUANGAN'] = $tanggal[0]['NAMA_RUANGAN'];
            }
            else{
                $query[$j]['TANGGAL'] = '0000-00-00';
                $query[$j]['NAMA_RUANGAN'] = '';
            }
            
            array_push($problem, $query[$j]);
        }
        
        
        $max_tab = 10;
        $count=count($problem);
        $add=0;
        $div = $max_tab;
        if ($count%$div!=0){
            $add=1;
        }
        $page = ($count - ($count%$div))/$div+$add;
        
        $j=0;
        $content = array();
        while($j<$max_tab && $j<count($problem) - ($hal-1)*$max_tab){
            $content[$j] = $problem[(($hal-1)*$max_tab)+$j];
            $j+=1;
        }
        $display['problem'] = $content;
        $display['page'] = $page;
        $display['curr_page'] = $hal;
        $display['stat'] = $stat;
        $display['id'] = $id;
        //$display['problem'] = $problem;
        $query = $this->db->query('select * from list_divisi')->result_array();
        $display['list_divisi'] = $query;
        $this->load->view('progress/header_view');
        $this->load->view('progress/problem_'.$stat.'_view', $display);
        $this->load->view('progress/footer_view');        
    }
    function problem_fix($table, $kode){ // table =2 -> sf, =1 -> komplain
        $display = array();
        if($table==1){ // complain
            $id=$kode;
            $query = $this->db->query('select * from komplain inner join user on komplain.ID_USER=user.ID where ID_KOMPLAIN='.$id)->result_array();
            if(count($query)>0) $display['problem'] = $query[0];
        }else if($table==2){ // sf
            $splitter = explode("_", $kode);
            $id = $splitter[0];
            $kode = $splitter[1];
            $angk= $splitter[2];
            $sesi = $splitter[3];
            $query = $this->db->query('select * from komentar_sesi inner join user on komentar_sesi.ID=user.ID where user.ID='.$id.' and KODE_PELATIHAN="'.$kode.'" and ANGKATAN='.$angk.' and NOMOR_SESI='.$sesi)->result_array();
            if(count($query)>0){
                $tanggal = $this->db->query('select * from daftar_jadwal inner join daftar_ruangan on daftar_jadwal.ID_RUANGAN=daftar_ruangan.ID_RUANGAN where KODE_PELATIHAN="'.$query[0]['KODE_PELATIHAN'].'" AND ANGKATAN='.$query[0]['ANGKATAN'].' AND NOMOR_SESI='.$query[0]['NOMOR_SESI'].'')->result_array();
                if(count($tanggal)>0){
                    $query[0]['TGL_KOMPLAIN'] = $tanggal[0]['TANGGAL'];
                    $query[0]['NAMA_RUANGAN'] = $tanggal[0]['NAMA_RUANGAN'];
                }
                else{
                    $query[0]['TGL_KOMPLAIN'] = '0000-00-00';
                    $query[0]['NAMA_RUANGAN'] = '';
                }
               $display['problem'] = $query[0];
            }
        }
        $this->load->view('progress/header_view');
        $this->load->view('progress/problem_fix_view', $display);
        $this->load->view('progress/footer_view');        
    }
    
    function problem_fix_process($option){
        if(empty($_POST['kode']) || empty($_POST['komentar']))
            redirect (base_url().'progress/progress_con/problem');
        $kode = $_POST['kode'];
        $komentar = $_POST['komentar'];
        if($option==1){ // komplain
            $id = $kode;
            $data = array(
                'STATUS_HANDLING' => 'HANDLED',
                'KOMENTAR_HANDLING' => $komentar,
                'ID_HANDLER' => $this->session->userdata('id'),
                'WAKTU_SOLVE' => date('H:i:s'),
                'TGL_SOLVE' => date('Y-m-d')
            );
            $this->db->where('ID_KOMPLAIN', $id);
            $this->db->update('komplain', $data);
        }else if($option==2){ // sf
            $splitter = explode("_", $kode);
            $id = $splitter[0];
            $kode = $splitter[1];
            $angk= $splitter[2];
            $sesi = $splitter[3];
            $data = array(
                'STATUS_HANDLING' => 'HANDLED',
                'KOMENTAR_HANDLING' => $komentar,
                'ID_HANDLER' => $this->session->userdata('id'),
                'WAKTU_SOLVE' => date('H:i:s'),
                'TGL_SOLVE' => date('Y-m-d')
            );
            $where = array(
                'ID' => $id,
                'KODE_PELATIHAN' =>$kode,
                'ANGKATAN' => $angk,
                'NOMOR_SESI' => $sesi
            );
            $this->db->where($where);
            $this->db->update('komentar_sesi', $data);
        }
        redirect(base_url().'progress/progress_con/problem_page/handled');
    }
    
    function problem_approve($option, $kode){
        if($option==1){ // komplain
            $id = $kode;
            $data = array(
                'STATUS_HANDLING' => 'SOLVED',
            );
            $this->db->where('ID_KOMPLAIN', $id);
            $this->db->update('komplain', $data);
        }else if($option==2){ // sf
            $splitter = explode("_", $kode);
            $id = $splitter[0];
            $kode = $splitter[1];
            $angk= $splitter[2];
            $sesi = $splitter[3];
            $data = array(
                'STATUS_HANDLING' => 'SOLVED',
            );
            $where = array(
                'ID' => $id,
                'KODE_PELATIHAN' =>$kode,
                'ANGKATAN' => $angk,
                'NOMOR_SESI' => $sesi
            );
            $this->db->where($where);
            $this->db->update('komentar_sesi', $data);
        }
        redirect(base_url().'progress/progress_con/problem_page/solved');        
    }
    
    function problem_reject($option, $kode){
        
        if($option==1){ // komplain
            $id = $kode;
            $data = array(
                'STATUS_HANDLING' => 'REJECTED',
            );
            $this->db->where('ID_KOMPLAIN', $id);
            $this->db->update('komplain', $data);
        }else if($option==2){ // sf
            $splitter = explode("_", $kode);
            $id = $splitter[0];
            $kode = $splitter[1];
            $angk= $splitter[2];
            $sesi = $splitter[3];
            $data = array(
                'STATUS_HANDLING' => 'REJECTED',
            );
            $where = array(
                'ID' => $id,
                'KODE_PELATIHAN' =>$kode,
                'ANGKATAN' => $angk,
                'NOMOR_SESI' => $sesi
            );
            $this->db->where($where);
            $this->db->update('komentar_sesi', $data);
        }
        redirect(base_url().'progress/progress_con/problem_page/rejected');
    }

    function change_pic_form(){
        $this->load->view('progress/header_view');
        $this->load->view('progress/change_pic_view');
        $this->load->view('progress/footer_view');                        
    }
    
    function change_pic(){
        $gallery_path = realpath(APPPATH . '../foto/');
        $config = array(
            'allowed_types'=>'jpg|jpeg|gif|png',
            'upload_path' => $gallery_path,
            'max_size' => 20000,
        );
        $this->load->library('upload',$config);
        $this->upload->do_custom_upload($this->session->userdata('nama').$this->session->userdata('id'),'userfile');
        $s = $this->upload->data();
        $this->session->set_userdata('temp_foto', base_url().'foto/'.$s['file_name']);
//        echo $this->session->userdata('temp_foto');
        redirect(base_url().'progress/progress_con/personal_bio_edit/'.$this->session->userdata('id'));
    }
    
}

?>
